﻿using MoneyManagerNET.Presentation.ViewModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using MoneyManagerNET.Model;

namespace Tests.Presentation.ViewModel
{
    
    
    /// <summary>
    ///This is a test class for TransactionViewModelTest and is intended
    ///to contain all TransactionViewModelTest Unit Tests
    ///</summary>
    [TestClass()]
    public class TransactionViewModelTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for TransactionViewModel Constructor
        ///</summary>
        [TestMethod()]
        public void TransactionViewModelConstructorTest()
        {
            TransactionViewModel target = new TransactionViewModel();
            Assert.Inconclusive("TODO: Implement code to verify target");
        }

        /// <summary>
        ///A test for AssociateToType
        ///</summary>
        [TestMethod()]
        [DeploymentItem("MoneyManagerNET.Presentation.ViewModel.dll")]
        public void AssociateToTypeTest()
        {
            TransactionViewModel_Accessor target = new TransactionViewModel_Accessor(); // TODO: Initialize to an appropriate value
            target.AssociateToType();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        #region
        ///// <summary>
        /////A test for LoadValues
        /////</summary>
        //[TestMethod()]
        //public void LoadValuesTest()
        //{
        //    TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
        //    ITransaction m = null; // TODO: Initialize to an appropriate value
        //    target.LoadValues(m);
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //}

        ///// <summary>
        /////A test for PromptCategory
        /////</summary>
        //[TestMethod()]
        //public void PromptCategoryTest()
        //{
        //    TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
        //    target.PromptCategory();
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //}

        ///// <summary>
        /////A test for PromptFromAccount
        /////</summary>
        //[TestMethod()]
        //public void PromptFromAccountTest()
        //{
        //    TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
        //    target.PromptFromAccount();
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //}

        ///// <summary>
        /////A test for PromptToAccount
        /////</summary>
        //[TestMethod()]
        //public void PromptToAccountTest()
        //{
        //    TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
        //    target.PromptToAccount();
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //}

        ///// <summary>
        /////A test for PropmptContragent
        /////</summary>
        //[TestMethod()]
        //public void PropmptContragentTest()
        //{
        //    TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
        //    target.PropmptContragent();
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //}

        ///// <summary>
        /////A test for PutValues
        /////</summary>
        //[TestMethod()]
        //public void PutValuesTest()
        //{
        //    TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
        //    ITransaction m = null; // TODO: Initialize to an appropriate value
        //    ITransaction expected = null; // TODO: Initialize to an appropriate value
        //    ITransaction actual;
        //    actual = target.PutValues(m);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}
        #endregion


        /// <summary>
        ///A test for Amount
        ///</summary>
        [TestMethod()]
        public void AmountTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value\

            decimal expected = 1000;
            var tran = CreateTransaction(expected);
            target.Model = tran;
            
            Decimal actual=target.Amount;
            
            Assert.AreEqual(expected, actual);
        }

        private static ITransaction CreateTransaction(decimal amount)
        {
            var from = MoneyManagerNET.App.Storage.New<IBankAccount>();
            from.Name = "test from account";
            from.Balance = 0;

            var categ = MoneyManagerNET.App.Storage.New<ICategory>();
            categ.Name = "food";

            var subcateg = MoneyManagerNET.App.Storage.New<ISubCategory>();
            subcateg.Name = "supermarket";
            subcateg.Category = categ;


            var contragent = MoneyManagerNET.App.Storage.New<IContragent>();
            contragent.Name = "pehi";

            var tran = MoneyManagerNET.App.Storage.New<ITransaction>();
            tran.Category = categ;
            tran.SubCategory = subcateg;
            tran.Contragent = contragent;
            tran.Amount = amount;
            tran.Date = DateTime.Now;
            tran.FromAccount = from;
            return tran;
        }

        /// <summary>
        ///A test for Category
        ///</summary>
        [TestMethod()]
        public void CategoryTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value

            bool ChangedFired = false;
            target.PropertyChanged += (o, e) => { if (e.PropertyName == "Category")ChangedFired = true; };
            //----------------------------------------
            var tran = CreateTransaction(100);
            target.Model = tran;
            //----------------------------------------
            Assert.IsTrue(ChangedFired, "should fire property change");
            Assert.AreEqual(tran.Category, target.Category, "category is not loaded into viewmodel");
            //Assert.IsFalse();
        }

        /// <summary>
        ///A test for CategoryContent
        ///</summary>
        [TestMethod()]
        public void CategoryContentTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value

            bool ChangedFired = false;
            target.PropertyChanged += (o, e) => { if (e.PropertyName == "CategoryContent")ChangedFired = true; };
            var initialCategoryLabel = target.CategoryContent;
            //----------------------------------------
            var tran = CreateTransaction(100);
            target.Model = tran;
            //----------------------------------------
            Assert.IsTrue(ChangedFired, "should fire property change");
            
            Assert.IsTrue(target.CategoryContent.ToString().Contains(target.Category.Name), "category name should be there");
            
        }

        /// <summary>
        ///A test for Contragent
        ///</summary>
        [TestMethod()]
        public void ContragentTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            IContragent expected = null; // TODO: Initialize to an appropriate value
            IContragent actual;
            target.Contragent = expected;
            actual = target.Contragent;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ContragentContent
        ///</summary>
        [TestMethod()]
        public void ContragentContentTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value

            bool ContragentContentChangedFired=false;
            target.PropertyChanged += (o, e) => { if (e.PropertyName == "Contragent")ContragentContentChangedFired = true; };
            var initialCategoryLabel = target.CategoryContent;
            //----------------------------------------
            var tran = CreateTransaction(100);
            target.Model = tran;
            //----------------------------------------
            Assert.IsTrue(ContragentContentChangedFired, "should fire property change");
            Assert.AreEqual(tran.Contragent,target.Contragent,"contragent is not loaded into viewmodel");
            Assert.IsTrue(target.ContragentContent.ToString().Contains(target.Contragent.Name),"contragent name should be there");
            //Assert.IsFalse();
        }

        /// <summary>
        ///A test for ContragentTitle
        ///</summary>
        [TestMethod()]
        public void ContragentTitleTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            string expected = string.Empty; // TODO: Initialize to an appropriate value
            string actual;
            target.ContragentTitle = expected;
            actual = target.ContragentTitle;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ContragentVisible
        ///</summary>
        [TestMethod()]
        public void ContragentVisibleTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            target.ContragentVisible = expected;
            actual = target.ContragentVisible;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for Date
        ///</summary>
        [TestMethod()]
        public void DateTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value
            DateTime actual;
            target.Date = expected;
            actual = target.Date;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for FromAccount
        ///</summary>
        [TestMethod()]
        public void FromAccountTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            IBankAccount expected = null; // TODO: Initialize to an appropriate value
            IBankAccount actual;
            target.FromAccount = expected;
            actual = target.FromAccount;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for FromContent
        ///</summary>
        [TestMethod()]
        public void FromContentTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            string actual;
            actual = target.FromContent;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for FromVisible
        ///</summary>
        [TestMethod()]
        public void FromVisibleTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            target.FromVisible = expected;
            actual = target.FromVisible;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for Notes
        ///</summary>
        [TestMethod()]
        public void NotesTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            string expected = string.Empty; // TODO: Initialize to an appropriate value
            string actual;
            target.Notes = expected;
            actual = target.Notes;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for PossibleStatuses
        ///</summary>
        [TestMethod()]
        public void PossibleStatusesTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            Array actual;
            actual = target.PossibleStatuses;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for PossibleTypes
        ///</summary>
        [TestMethod()]
        public void PossibleTypesTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            Array actual;
            actual = target.PossibleTypes;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for Status
        ///</summary>
        [TestMethod()]
        public void StatusTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            TransactionStatus expected = new TransactionStatus(); // TODO: Initialize to an appropriate value
            TransactionStatus actual;
            target.Status = expected;
            actual = target.Status;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for SubCategory
        ///</summary>
        [TestMethod()]
        public void SubCategoryTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value

            bool ChangedFired = false;
            target.PropertyChanged += (o, e) => { if (e.PropertyName == "SubCategory")ChangedFired = true; };
            //----------------------------------------
            var tran = CreateTransaction(100);
            target.Model = tran;
            //----------------------------------------
            Assert.IsTrue(ChangedFired, "should fire property change");
            Assert.AreEqual(tran.SubCategory, target.SubCategory, "subcategory is not loaded into viewmodel");
        }

        /// <summary>
        ///A test for ToAccount
        ///</summary>
        [TestMethod()]
        public void ToAccountTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            IBankAccount expected = null; // TODO: Initialize to an appropriate value
            IBankAccount actual;
            target.ToAccount = expected;
            actual = target.ToAccount;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ToContent
        ///</summary>
        [TestMethod()]
        public void ToContentTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            string actual;
            actual = target.ToContent;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ToVisible
        ///</summary>
        [TestMethod()]
        public void ToVisibleTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            target.ToVisible = expected;
            actual = target.ToVisible;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for TransactionType
        ///</summary>
        [TestMethod()]
        public void TransactionTypeTest()
        {
            TransactionViewModel target = new TransactionViewModel(); // TODO: Initialize to an appropriate value
            TransactionType expected = new TransactionType(); // TODO: Initialize to an appropriate value
            TransactionType actual;
            target.TransactionType = expected;
            actual = target.TransactionType;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
    }
}
